<template>
  <div>
    <div class="list">
      <i
        data-v-ceafbf5a=""
        class="el-icon-s-order"
        style="font-size: 30px; color: rgb(255, 103, 0)"
      ></i>
      我的订单
    </div>
    <hr />

    <div class="shuju">
      <div class="item" v-for="(item, index) in order" :key="index">
        <div class="item-list">
          <p style="color: #ff6700">&emsp;订单编号：{{ item[0].order_id }}</p>
          <p>订单时间：{{ item[0].order_time }}&emsp;</p>
        </div>
        <table>
          <tr>
            <th>商品名称</th>
            <th>单价</th>
            <th>数量</th>
            <th>小计</th>
          </tr>
          <tr v-for="it in item" :key="it.id">
            <td>
              <img
                :src="'http://101.132.181.9:3000/' + it.product_picture"
                alt=""
              />{{ it.product_name }}
            </td>
            <td>{{ it.product_price }}</td>
            <td>{{ it.product_num }}</td>
            <td>{{ it.product_num * it.product_price }}</td>
            <td></td>
          </tr>
        </table>
        <div class="s1">
          <p>&emsp;共{{ priceAll.allnum }}件商品</p>
          <p>合计{{ priceAll.checkPrace }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { GetorderList } from "@/api/shop";
export default {
  name: "order",
  data() {
    return {
      order: [],
      userId: this.$store.state.users.user_id,
    };
  },
  computed: {
    // priceAll(){
    //   var allnum=0
    //   this.order.forEach((it)=>{
    //     allnum+=it.product_num*it.product_price
    //   })
    //   return {allnum}
    // }
    priceAll() {
      var allnum = 0;
      var checkPrace = 0;
      for (const item in this.order) {
        console.log(this.order[item]);
        for (const key in this.order[item]) {
          let it = this.order[item][key];
          allnum += it.product_num;
          checkPrace += it.product_num * it.product_price;
        }
      }
      return { allnum, checkPrace };
    },
  },
  created() {
    this.orderConfirm();
  },
  methods: {
    async orderConfirm() {
      let res = await GetorderList({ user_id: this.userId });
      console.log(res.orders);
      this.order = res.orders;
    },
  },
};
</script>

<style lang="scss" scoped>
.s1 {
  width: 100%;
  height: 60px;
  background-color: aqua;
  display: flex;
  justify-content: space-between;
  font-size: 25px;
  align-items: center;
}
table {
  width: 100%;
  border-bottom: 1px solid #e0e0e0;
  text-align: center;
  img {
    width: 50px;
    height: 50px;
  }
}
.list {
  width: 80%;
  height: 64px;
  margin: auto;
  height: 64px;
  line-height: 58px;
  font-size: 28px;
}
hr {
  background-color: red;
}
.shuju {
  width: 100%;
  background-color: #f5f5f5;

  .item {
    width: 80%;
    height: 100%;
    background-color: white;
    margin: auto;
    .item-list {
      width: 100%;
      height: 61px;
      background-color: white;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid red;
      margin-top: 60px;
    }
  }
}
</style>